Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "wait for all" not resolving when given empty list of promises #58

Merged
merged 4 commits into from
Jul 16, 2019
Merged

Fix "wait for all" not resolving when given empty list of promises #58

merged 4 commits into from
Jul 16, 2019

Conversation

MattiasBuelens
Copy link
Contributor

From my comment on whatwg/streams#1004:

The steps in the "wait for all" algorithm do not account for the case where promises is an empty list! It attaches a fulfillmentHandler to every promise in promises, and checks whether we're done only inside that handler. But if no promises were passed in, then no handlers are attached and we never check whether we're done.

The fix is obvious: if the list of promises passed to the "wait for all" algorithm is empty, then it should immediately call successSteps with an empty list.

@ricea
Copy link

ricea commented Jul 16, 2019

I think there could be a problem here. If I'm reading it correctly, we're calling successSteps synchronously when the list is empty, but asynchronously in all other cases.

Maybe it needs to be something like "queue a microtask to run successSteps"?

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking this on! Agreed we should queue a microtask.

index.bs Outdated Show resolved Hide resolved
@MattiasBuelens
Copy link
Contributor Author

Would this work?

  1. If total is 0, then queue a microtask to perform successSteps given result and return.

I feel like it might be confusing whether "and return" is still part of the outer algorithm, or whether it's part of the steps inside the microtask.

Would you prefer I change it to this instead?

  1. If total is 0, then:
    1. Queue a microtask to perform successSteps given result.
    2. Return.

@domenic
Copy link
Member

domenic commented Jul 16, 2019

Nested steps seems slightly better; thanks!

I also need to investigate the build failures, hrm.

@@ -269,6 +272,9 @@ To <dfn id="waiting-for-all" export lt="wait for all|waiting for all">wait for a
1. Let |index| be 0.
1. Let |total| be |promises|'s [=list/size=].
1. Let |result| be a <a>list</a> containing |total| null values.
1. If |total| is 0, then:
1. <a>Queue a microtask</a> to perform |successSteps| given |result|.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I'm doing this autolinking right! 😅

I still don't know when to use "dfn autolinks" ([= ... =]) and when to use manual <a> elements though... 🤷‍♂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're equivalent. Basically [=...=] is newer so some older specs like this one still use <a>. (And also sometimes newer specs written by people with older habits.)

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the link-defaults changes which should not be necessary.

@domenic domenic merged commit 135dddc into w3ctag:master Jul 16, 2019
domenic pushed a commit to web-platform-tests/wpt that referenced this pull request Jul 16, 2019
@MattiasBuelens MattiasBuelens deleted the fix-wait-for-all-on-empty-list branch July 16, 2019 23:01
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 24, 2019
…eventCancel and preventAbort works, a=testonly

Automatic update from web-platform-tests
Streams: verify that aborting a pipe with both preventCancel and preventAbort works

See whatwg/streams#1004 and w3ctag/promises-guide#58.
--

wpt-commits: 0da3476dcd5fd3148041d090d2330cf8d412d7f9
wpt-pr: 17816
xeonchen pushed a commit to xeonchen/gecko that referenced this pull request Jul 25, 2019
…eventCancel and preventAbort works, a=testonly

Automatic update from web-platform-tests
Streams: verify that aborting a pipe with both preventCancel and preventAbort works

See whatwg/streams#1004 and w3ctag/promises-guide#58.
--

wpt-commits: 0da3476dcd5fd3148041d090d2330cf8d412d7f9
wpt-pr: 17816
domenic pushed a commit to whatwg/streams that referenced this pull request Jul 29, 2019
When both the preventCancel and preventAbort flags are set, the abortAlgorithm passes an empty list of actions to "wait for all". This helper should immediately resolve the returned promise when no promises are given, but instead the promise remained pending forever.

This fixes the reference implementation of the "wait for all" helper to resolve correctly when given an empty list of promises. This matches the spec change in w3ctag/promises-guide#58.

Originally reported in #1004 (comment).
natechapin pushed a commit to natechapin/wpt that referenced this pull request Aug 23, 2019
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 4, 2019
…eventCancel and preventAbort works, a=testonly

Automatic update from web-platform-tests
Streams: verify that aborting a pipe with both preventCancel and preventAbort works

See whatwg/streams#1004 and w3ctag/promises-guide#58.
--

wpt-commits: 0da3476dcd5fd3148041d090d2330cf8d412d7f9
wpt-pr: 17816

UltraBlame original commit: 40dd37dfbbfbc0659c81c2a386f5fe966b3c8203
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 4, 2019
…eventCancel and preventAbort works, a=testonly

Automatic update from web-platform-tests
Streams: verify that aborting a pipe with both preventCancel and preventAbort works

See whatwg/streams#1004 and w3ctag/promises-guide#58.
--

wpt-commits: 0da3476dcd5fd3148041d090d2330cf8d412d7f9
wpt-pr: 17816

UltraBlame original commit: 40dd37dfbbfbc0659c81c2a386f5fe966b3c8203
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 4, 2019
…eventCancel and preventAbort works, a=testonly

Automatic update from web-platform-tests
Streams: verify that aborting a pipe with both preventCancel and preventAbort works

See whatwg/streams#1004 and w3ctag/promises-guide#58.
--

wpt-commits: 0da3476dcd5fd3148041d090d2330cf8d412d7f9
wpt-pr: 17816

UltraBlame original commit: 40dd37dfbbfbc0659c81c2a386f5fe966b3c8203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants